package cn.javaeye.lonlysky.lforum.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.config.ParentPackage;

import cn.javaeye.lonlysky.lforum.ForumBaseAction;
import cn.javaeye.lonlysky.lforum.entity.web.FartherType;
import cn.javaeye.lonlysky.lforum.entity.web.ParentType;
import cn.javaeye.lonlysky.lforum.service.InfoManager;
import cn.javaeye.lonlysky.lforum.service.ParentTypeManager;

/**
 * 
 * 
 * @author fishkang
 *
 */
@ParentPackage("default")
public class webIndexAction extends ForumBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 550816793720191618L;
	private InfoManager infoManager;
	private ParentTypeManager parentTypeManager;
	private List<FartherType> fartherTypeList;
	@SuppressWarnings("unchecked")
	private List<Map> MapList =new ArrayList();
 	@SuppressWarnings("unchecked")
	@Override
	public String execute()  {
 		fartherTypeList=fartherTypeManager.findByType("0");
 		for (int i = 0; i < fartherTypeList.size(); i++) {
 			Map map=new HashMap();
 			//父类型
 			map.put("farther", fartherTypeList.get(i));
 			List<ParentType> parentTypeList=parentTypeManager.findByFid(fartherTypeList.get(i).getId());
 			if (parentTypeList.size()==1) {
 				map.put("parentType1", parentTypeList.get(0));
 				map.put("parentType2","");
 				map.put("list1", infoManager.findInfoParther(parentTypeList.get(0).getId()));
 				map.put("list2", "");
			}else if (parentTypeList.size()>=2) {
 				map.put("parentType1", parentTypeList.get(0));
 				map.put("parentType2",parentTypeList.get(1));
 				map.put("list1", infoManager.findInfoParther(parentTypeList.get(0).getId()));
 				map.put("list2", infoManager.findInfoParther(parentTypeList.get(1).getId()));
			} else {
 				map.put("parentType1","");
 				map.put("parentType2","");
 				map.put("list1", "");
 				map.put("list2", "");
			}
 			MapList.add(map);
		}
		return SUCCESS;
	}
	public List<FartherType> getFartherTypeList() {
		return fartherTypeList;
	}
	public void setFartherTypeList(List<FartherType> fartherTypeList) {
		this.fartherTypeList = fartherTypeList;
	}
	public InfoManager getInfoManager() {
		return infoManager;
	}
	public void setInfoManager(InfoManager infoManager) {
		this.infoManager = infoManager;
	}
	public ParentTypeManager getParentTypeManager() {
		return parentTypeManager;
	}
	public void setParentTypeManager(ParentTypeManager parentTypeManager) {
		this.parentTypeManager = parentTypeManager;
	}
	@SuppressWarnings("unchecked")
	public List<Map> getMapList() {
		return MapList;
	}
	@SuppressWarnings("unchecked")
	public void setMapList(List<Map> mapList) {
		MapList = mapList;
	}
	
}
